package com.wuzheng.wisgo.sanitation.cloud.controller.jobcompletion;


import com.wuzheng.wisgo.sanitation.cloud.enums.MapTypeEnum;
import com.wuzheng.wisgo.sanitation.cloud.model.roadandstatus.ReceviceLngLatDto;
import com.wuzheng.wisgo.sanitation.cloud.model.tbox.pojo.ReceiveInfoSelectAllDto;
import com.wuzheng.wisgo.sanitation.cloud.paraandgetutil.VehicleException;
import com.wuzheng.wisgo.sanitation.cloud.repository.entity.jobcompletion.BaJobCompletion;
import com.wuzheng.wisgo.sanitation.cloud.repository.mapper.tbox.ReceiveInfoMapper;
import com.wuzheng.wisgo.sanitation.cloud.service.jobcompletion.BaJobCompletionService;
import com.wuzheng.wisgo.sanitation.cloud.service.roadandstatus.RouteStateService;
import com.wuzheng.wisgo.sanitation.framework.base.controller.BaseController;
import com.wuzheng.wisgo.sanitation.framework.core.protocol.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * @author：sp
 * @date：Created in 2019-12-19
 * @description：作业完成情况表控制器
 * @modified By：
 * @version: 1.0
 */
@RestController
@RequestMapping("/baJobCompletion")
@Api(value = "BaJobCompletionCtrl", tags = "作业完成情况表接口")
public class BaJobCompletionCtrl extends BaseController {

    @Autowired
    private BaJobCompletionService baJobCompletionService;

    @Autowired
    private ReceiveInfoMapper receiveInfoMapper;

    @Autowired
    private RouteStateService routeStateService;

    /**
     * 获取作业完成情况表列表
     */
    @PostMapping(value = "/list")
    @ApiOperation(value = "获取作业完成情况表列表")
    public Result<List<BaJobCompletion>> list() {
        return this.success(baJobCompletionService.selectList());
    }

    /**
     * 新增作业完成情况表
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增作业完成情况表")
    public Result<String> add(BaJobCompletion baJobCompletion) {
        baJobCompletionService.insert(baJobCompletion);
        return this.success();
    }

    /**
     * 删除作业完成情况表
     */
    @PostMapping(value = "/delete/{id}")
    @ApiOperation(value = "删除作业完成情况表")
    public Result<String> delete(@PathVariable("id") Long id) {
        baJobCompletionService.deleteById(id);
        return this.success();
    }

    /**
     * 修改作业完成情况表
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改作业完成情况表")
    public Result<String> update(BaJobCompletion baJobCompletion) {
        baJobCompletionService.updateById(baJobCompletion);
        return this.success();
    }

    /**
     * 获取作业完成情况表
     */
    @GetMapping(value = "/get/{id}")
    @ApiOperation(value = "获取作业完成情况表")
    public Result<BaJobCompletion> get(@PathVariable("id") Long id) {
        return this.success(baJobCompletionService.selectById(id));
    }


    /**
     * 获取作业完成情况表
     */
    @PostMapping(value = "/test")
    @ApiOperation(value = "测试")
    public Result<BaJobCompletion> getTest(@RequestBody String vehCode,String starTime,String stopTime) {
        List<ReceiveInfoSelectAllDto> receiveInfos = receiveInfoMapper.selectByLongLatInfo("wz", MapTypeEnum.GAODE.getTypeId(),
                vehCode, Timestamp.valueOf(starTime),Timestamp.valueOf(stopTime));
        if(receiveInfos.size()>0){
            for(ReceiveInfoSelectAllDto receiveInfo:receiveInfos){
                ReceviceLngLatDto receviceLngLatDto=new ReceviceLngLatDto();
                receviceLngLatDto.setVehVin(receiveInfo.getRecVin());
                receviceLngLatDto.settLongitude(receiveInfo.gettTranLongitude());
                receviceLngLatDto.settLatitude(receiveInfo.gettTranLatitude());
                receviceLngLatDto.setLongitude(receiveInfo.getRecLongitude());
                receviceLngLatDto.setLatitude(receiveInfo.getRecLatitude());
                receviceLngLatDto.setRecCollectionTime(receiveInfo.getRecCollectionTime());
                try {
                    routeStateService.roadJudgeStatus(receviceLngLatDto);
                } catch (VehicleException e) {
                    e.printStackTrace();
                }
            }
        }
        return this.success("成功");
    }
}

